package org.raymond.iworks.apis.avro;

import org.apache.commons.lang3.time.DateFormatUtils;

public class LogModelToString {
    private static final String NORM_DATETIME_MS_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";

    public static String toString(LogModel logModel){
        StringBuilder log = new StringBuilder();

        String clientTimeStr = logModel.getClientTime()==null?"":DateFormatUtils.format(logModel.getClientTime(), NORM_DATETIME_MS_FORMAT);
        String startTimeStr = logModel.getStartTime()==null?"":DateFormatUtils.format(logModel.getStartTime(), NORM_DATETIME_MS_FORMAT);
        String endTimeStr = logModel.getEndTime()==null?"":DateFormatUtils.format(logModel.getEndTime(), NORM_DATETIME_MS_FORMAT);

        log.append("RequestIP:").append(logModel.getRequestURI()).append(",RequestURI:").append(logModel.getRequestURI())
                .append(",Method:").append(logModel.getMethod()).append(",ClientTime:").append(clientTimeStr)
                .append(",Headers:").append(logModel.getHeaders()).append(",Params:").append(logModel.getParams())
                .append(",Request:").append(logModel.getRequest()).append(",Response:").append(logModel.getResponse())
                .append(",Status:").append(logModel.getStatus())
                .append(",StartTime:").append(startTimeStr).append(",EndTime:").append(endTimeStr)
                ;
        return log.toString();
    }
}
